/**
 * 
 */
package com.app.service.impl.getvoimpl;

import java.io.IOException;
import java.io.InputStream;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.app.service.BaseService;
import com.app.service.BaseVo;
import com.app.service.IGetBasePointVo;
import com.app.service.vo.DNAVo;

/**
 * @author yuxk
 * 针对玉米种子dna模板获取dna值对象
 */
public class GetBasePointVoByCornImpl extends BaseService implements IGetBasePointVo {

	/**
	 * 
	 */
	public GetBasePointVoByCornImpl() {
		// TODO Auto-generated constructor stub
		logger.info(this.getClass().getName()+" loader");
	}
	
	private static Logger logger = Logger.getLogger(GetBasePointVoByCornImpl.class);

	/* (non-Javadoc)
	 * @see com.app.service.IGetBasePointVo#getBaseVo(java.io.InputStream)
	 */
	@Override
	public BaseVo getBaseVo(InputStream input) {
		logger.info("玉米DNA数据解析开始");
		DNAVo vo = new DNAVo();
		try {			
			HSSFWorkbook hwb = new HSSFWorkbook(input);
			HSSFSheet hs = hwb.getSheetAt(0);
			HSSFRow row = hs.getRow(hs.getLastRowNum());
			String dnaCoder = row.getCell(0).getStringCellValue();
			String dnaName  = row.getCell(1).getStringCellValue();
			String dnatype  = row.getCell(3).getStringCellValue(); 
			String dbasource = row.getCell(2).getStringCellValue();
			vo.setDnaCoder(dnaCoder);
			vo.setDnaName(dnaName);
			vo.setDnatype(dnatype);
			vo.setDnasource(dbasource);			
			for(int i=4;i<row.getLastCellNum();i++){
				HSSFCell cell = row.getCell(i);
				int value = (int) cell.getNumericCellValue();
				vo.setPointsum(value);
				if(i-3<=40){
					vo.getValues().put("P"+this.getPointCoder(i-3), value);
				}
			}
		} catch (IOException e) {
			logger.info("玉米DNA数据解析失败");
			logger.error(e);
		}
		try {
			input.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		logger.info("玉米DNA数据解析成功");
		return vo;
	}

	private String getPointCoder(int i)
	{
		String coder = String.valueOf(i);
		if(10-i>0)
		{
			coder = "0"+coder;
		}
		return coder;
	}
	
//	static public void main(String arg[]) throws FileNotFoundException
//	{
//		System.out.println(new GetBasePointVoByCornImpl().getBaseVo(new FileInputStream("c:\\key1 - 副本.xls")));
//	}
}
